package com.oim.fx.ui.user;

import java.util.List;

import com.oim.fx.ui.component.WaitingPanel;

import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.Background;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;

/**
 * @author: XiaHui
 * @date: 2017年4月11日 上午10:14:29
 */
public class HeadListPanel extends VBox {
	
	StackPane centerPane = new StackPane();
	FlowPane flowPane = new FlowPane();
	WaitingPanel waitingPanel = new WaitingPanel();
	ScrollPane scrollPane = new ScrollPane();
	public HeadListPanel() {
		initComponent();
		initEvent();
	}

	private void initComponent() {
		this.getChildren().add(centerPane);

		flowPane.setPadding(new Insets(15, 10, 0, 10));
		flowPane.setVgap(10);
		flowPane.setHgap(10);
		flowPane.setPrefWrapLength(900); // 预设流面板的宽度，使得能够显示两列

		scrollPane.setBackground(Background.EMPTY);
		scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
		scrollPane.setContent(flowPane);

		centerPane.getChildren().add(scrollPane);
		centerPane.getChildren().add(waitingPanel);

		centerPane.setStyle("-fx-background-color:rgba(255, 255, 255, 0.7)");
		VBox.setVgrow(centerPane, Priority.ALWAYS);
		this.showWaiting(false, WaitingPanel.show_waiting);
	}

	private void initEvent() {

	}
	public void showWaiting(boolean show, String key) {
		waitingPanel.setVisible(show);
		flowPane.setVisible(!show);
		waitingPanel.show(key);
	}

	public void setNodeList(List<? extends Node> nodeList) {
		flowPane.getChildren().clear();
		flowPane.getChildren().addAll(nodeList);
	}

	public void setPrefWrapLength(double length) {
		flowPane.setPrefWrapLength(length);
	}

	public void setVgap(double value) {
		flowPane.setVgap(value);
	}

	public void setHgap(double value) {
		flowPane.setHgap(value);
	}
}
